package com.kanq.service.designpatterns.singleton;

import lombok.Data;

/**
 * @Author cheng jun
 * @Description: 懒汉式：解决了线程同步问题，但是没有解决反序列化问题
 * @Date 2021/7/13 19:44
 */
public class Demo2 {
    private Demo2() {
    }

    private static class InnerDemo {
        private static final Demo2 INSTANCE = new Demo2();
    }

    public static Demo2 getInstance() {
        return InnerDemo.INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                System.out.println(getInstance().hashCode());
            }).start();
        }
    }
}

